/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CrudMasterView.java
 *
 * Created on 19/07/2010, 09:39:37
 */

package crud;

import domain.Clientes;
import facade.ClienteFacade;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.Action;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


/**
 *
 * @author vntraal
 */
public class CrudMasterView extends javax.swing.JFrame
                            implements CrudBasicMethods{

    /** Creates new form CrudMasterView */
    private CrudMasterViewCtrl crudMstCtrl;
    private ClienteFacade instance = null;

    public CrudMasterView() {
        
        crudMstCtrl = new CrudMasterViewCtrl(this);
        initComponents();

        ApplicationContext context = new
                ClassPathXmlApplicationContext("applicationContext.xml");

        this.instance = (ClienteFacade)context.getBean("clienteFacade");
        jPanelEdit.setVisible(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        clientesList = listAllRecords();
        clientes = new Clientes();
        jPanel1 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jBtnNew = new javax.swing.JButton();
        jBtnEdit = new javax.swing.JButton();
        jBtnRemove = new javax.swing.JButton();
        jBtnSearch = new javax.swing.JButton();
        jSepSave = new javax.swing.JToolBar.Separator();
        jBtnSave = new javax.swing.JButton();
        jBtnCancel = new javax.swing.JButton();
        jSepExit = new javax.swing.JToolBar.Separator();
        jBtnExit = new javax.swing.JButton();
        jLayeredPaneControl = new javax.swing.JLayeredPane();
        jPanelEdit = new javax.swing.JPanel();
        jLabelEditID = new javax.swing.JLabel();
        jTextFieldEditID = new javax.swing.JTextField();
        jTextFieldEditNome = new javax.swing.JTextField();
        jLabelNome = new javax.swing.JLabel();
        jLabelNasc = new javax.swing.JLabel();
        jFormattedTextFieldNasc = new javax.swing.JFormattedTextField();
        jPanelSearch = new javax.swing.JPanel();
        jScrollPaneSearch = new javax.swing.JScrollPane();
        jTableSearch = new javax.swing.JTable();
        jTextFieldSearchID = new javax.swing.JTextField();
        jLabelSearchID = new javax.swing.JLabel();
        jBtnExecSearch = new javax.swing.JButton();

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, clientes, org.jdesktop.beansbinding.ELProperty.create("${id}"), clientes, org.jdesktop.beansbinding.BeanProperty.create("id"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, clientes, org.jdesktop.beansbinding.ELProperty.create("${nascimento}"), clientes, org.jdesktop.beansbinding.BeanProperty.create("nascimento"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, clientes, org.jdesktop.beansbinding.ELProperty.create("${nome}"), clientes, org.jdesktop.beansbinding.BeanProperty.create("nome"));
        bindingGroup.addBinding(binding);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(swinghelloworld.SwingHelloWorldApp.class).getContext().getResourceMap(CrudMasterView.class);
        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(swinghelloworld.SwingHelloWorldApp.class).getContext().getActionMap(CrudMasterView.class, this);
        jBtnNew.setAction(actionMap.get("doInsert")); // NOI18N
        jBtnNew.setBackground(resourceMap.getColor("jBtnNew.background")); // NOI18N
        jBtnNew.setIcon(resourceMap.getIcon("jBtnNew.icon")); // NOI18N
        jBtnNew.setText(resourceMap.getString("jBtnNew.text")); // NOI18N
        jBtnNew.setFocusable(false);
        jBtnNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnNew.setName("jBtnNew"); // NOI18N
        jBtnNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBtnNew);

        jBtnEdit.setAction(actionMap.get("doEdit")); // NOI18N
        jBtnEdit.setBackground(resourceMap.getColor("jBtnEdit.background")); // NOI18N
        jBtnEdit.setIcon(resourceMap.getIcon("jBtnEdit.icon")); // NOI18N
        jBtnEdit.setText(resourceMap.getString("jBtnEdit.text")); // NOI18N
        jBtnEdit.setFocusable(false);
        jBtnEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnEdit.setName("jBtnEdit"); // NOI18N
        jBtnEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBtnEdit);

        jBtnRemove.setAction(actionMap.get("doRemove")); // NOI18N
        jBtnRemove.setBackground(resourceMap.getColor("jBtnRemove.background")); // NOI18N
        jBtnRemove.setIcon(resourceMap.getIcon("jBtnRemove.icon")); // NOI18N
        jBtnRemove.setText(resourceMap.getString("jBtnRemove.text")); // NOI18N
        jBtnRemove.setFocusable(false);
        jBtnRemove.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnRemove.setName("jBtnRemove"); // NOI18N
        jBtnRemove.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBtnRemove);

        jBtnSearch.setAction(actionMap.get("doSearch")); // NOI18N
        jBtnSearch.setBackground(resourceMap.getColor("jBtnSearch.background")); // NOI18N
        jBtnSearch.setIcon(resourceMap.getIcon("jBtnSearch.icon")); // NOI18N
        jBtnSearch.setText(resourceMap.getString("jBtnSearch.text")); // NOI18N
        jBtnSearch.setFocusable(false);
        jBtnSearch.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnSearch.setName("jBtnSearch"); // NOI18N
        jBtnSearch.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBtnSearch);

        jSepSave.setName("jSepSave"); // NOI18N
        jToolBar1.add(jSepSave);

        jBtnSave.setAction(actionMap.get("doSave")); // NOI18N
        jBtnSave.setBackground(resourceMap.getColor("jBtnSave.background")); // NOI18N
        jBtnSave.setIcon(resourceMap.getIcon("jBtnSave.icon")); // NOI18N
        jBtnSave.setText(resourceMap.getString("jBtnSave.text")); // NOI18N
        jBtnSave.setFocusable(false);
        jBtnSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnSave.setName("jBtnSave"); // NOI18N
        jBtnSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBtnSave);

        jBtnCancel.setAction(actionMap.get("doCancel")); // NOI18N
        jBtnCancel.setBackground(resourceMap.getColor("jBtnCancel.background")); // NOI18N
        jBtnCancel.setIcon(resourceMap.getIcon("jBtnCancel.icon")); // NOI18N
        jBtnCancel.setText(resourceMap.getString("jBtnCancel.text")); // NOI18N
        jBtnCancel.setFocusable(false);
        jBtnCancel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnCancel.setName("jBtnCancel"); // NOI18N
        jBtnCancel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBtnCancel);

        jSepExit.setName("jSepExit"); // NOI18N
        jToolBar1.add(jSepExit);

        jBtnExit.setAction(actionMap.get("doExit")); // NOI18N
        jBtnExit.setBackground(resourceMap.getColor("jBtnExit.background")); // NOI18N
        jBtnExit.setIcon(resourceMap.getIcon("jBtnExit.icon")); // NOI18N
        jBtnExit.setText(resourceMap.getString("jBtnExit.text")); // NOI18N
        jBtnExit.setFocusable(false);
        jBtnExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBtnExit.setName("jBtnExit"); // NOI18N
        jBtnExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBtnExit);

        jLayeredPaneControl.setBackground(resourceMap.getColor("jLayeredPaneControl.background")); // NOI18N
        jLayeredPaneControl.setName("jLayeredPaneControl"); // NOI18N

        jPanelEdit.setBackground(resourceMap.getColor("jPanelEdit.background")); // NOI18N
        jPanelEdit.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanelEdit.border.title"))); // NOI18N
        jPanelEdit.setName("jPanelEdit"); // NOI18N

        jLabelEditID.setText(resourceMap.getString("jLabelEditID.text")); // NOI18N
        jLabelEditID.setName("jLabelEditID"); // NOI18N

        jTextFieldEditID.setName("jTextFieldEditID"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTableSearch, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), jTextFieldEditID, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextFieldEditNome.setName("jTextFieldEditNome"); // NOI18N

        jLabelNome.setText(resourceMap.getString("jLabelNome.text")); // NOI18N
        jLabelNome.setName("jLabelNome"); // NOI18N

        jLabelNasc.setText(resourceMap.getString("jLabelNasc.text")); // NOI18N
        jLabelNasc.setName("jLabelNasc"); // NOI18N

        jFormattedTextFieldNasc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
        jFormattedTextFieldNasc.setText(resourceMap.getString("jFormattedTextFieldNasc.text")); // NOI18N
        jFormattedTextFieldNasc.setName("jFormattedTextFieldNasc"); // NOI18N

        javax.swing.GroupLayout jPanelEditLayout = new javax.swing.GroupLayout(jPanelEdit);
        jPanelEdit.setLayout(jPanelEditLayout);
        jPanelEditLayout.setHorizontalGroup(
            jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelEditLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldEditID, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEditID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldEditNome, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNome))
                .addGap(24, 24, 24)
                .addGroup(jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelNasc)
                    .addComponent(jFormattedTextFieldNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(165, Short.MAX_VALUE))
        );
        jPanelEditLayout.setVerticalGroup(
            jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelEditLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelEditLayout.createSequentialGroup()
                        .addGroup(jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelEditID)
                            .addComponent(jLabelNasc))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldEditID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jFormattedTextFieldNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelEditLayout.createSequentialGroup()
                        .addComponent(jLabelNome)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldEditNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jPanelEdit.setBounds(0, 0, 570, 90);
        jLayeredPaneControl.add(jPanelEdit, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanelSearch.setBackground(resourceMap.getColor("jPanelSearch.background")); // NOI18N
        jPanelSearch.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanelSearch.border.title"))); // NOI18N
        jPanelSearch.setName("jPanelSearch"); // NOI18N

        jScrollPaneSearch.setName("jScrollPaneSearch"); // NOI18N

        jTableSearch.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableSearch.setName("jTableSearch"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, clientes, org.jdesktop.beansbinding.ObjectProperty.create(), jTableSearch, org.jdesktop.beansbinding.BeanProperty.create("selectedElement"));
        bindingGroup.addBinding(binding);

        jScrollPaneSearch.setViewportView(jTableSearch);

        jTextFieldSearchID.setName("jTextFieldSearchID"); // NOI18N

        jLabelSearchID.setText(resourceMap.getString("jLabelSearchID.text")); // NOI18N
        jLabelSearchID.setName("jLabelSearchID"); // NOI18N

        jBtnExecSearch.setAction(actionMap.get("doExecSearch")); // NOI18N
        jBtnExecSearch.setText(resourceMap.getString("jBtnExecSearch.text")); // NOI18N
        jBtnExecSearch.setName("jBtnExecSearch"); // NOI18N

        javax.swing.GroupLayout jPanelSearchLayout = new javax.swing.GroupLayout(jPanelSearch);
        jPanelSearch.setLayout(jPanelSearchLayout);
        jPanelSearchLayout.setHorizontalGroup(
            jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPaneSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabelSearchID)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelSearchLayout.createSequentialGroup()
                            .addComponent(jTextFieldSearchID, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jBtnExecSearch))))
                .addContainerGap(96, Short.MAX_VALUE))
        );
        jPanelSearchLayout.setVerticalGroup(
            jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelSearchID)
                .addGap(4, 4, 4)
                .addGroup(jPanelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSearchID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtnExecSearch))
                .addGap(29, 29, 29)
                .addComponent(jScrollPaneSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(302, 302, 302))
        );

        jPanelSearch.setBounds(0, 0, 570, 250);
        jLayeredPaneControl.add(jPanelSearch, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)
                .addGap(51, 51, 51))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLayeredPaneControl, javax.swing.GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPaneControl, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
                .addGap(27, 27, 27))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private domain.Clientes clientes;
    private java.util.List<domain.Clientes> clientesList;
    private javax.swing.JButton jBtnCancel;
    private javax.swing.JButton jBtnEdit;
    private javax.swing.JButton jBtnExecSearch;
    private javax.swing.JButton jBtnExit;
    private javax.swing.JButton jBtnNew;
    private javax.swing.JButton jBtnRemove;
    private javax.swing.JButton jBtnSave;
    private javax.swing.JButton jBtnSearch;
    private javax.swing.JFormattedTextField jFormattedTextFieldNasc;
    private javax.swing.JLabel jLabelEditID;
    private javax.swing.JLabel jLabelNasc;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelSearchID;
    private javax.swing.JLayeredPane jLayeredPaneControl;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelEdit;
    private javax.swing.JPanel jPanelSearch;
    private javax.swing.JScrollPane jScrollPaneSearch;
    private javax.swing.JToolBar.Separator jSepExit;
    private javax.swing.JToolBar.Separator jSepSave;
    private javax.swing.JTable jTableSearch;
    private javax.swing.JTextField jTextFieldEditID;
    private javax.swing.JTextField jTextFieldEditNome;
    private javax.swing.JTextField jTextFieldSearchID;
    private javax.swing.JToolBar jToolBar1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the jBtnCancel
     */
    public javax.swing.JButton getjBtnCancel() {
        return jBtnCancel;
    }

    /**
     * @param jBtnCancel the jBtnCancel to set
     */
    public void setjBtnCancel(javax.swing.JButton jBtnCancel) {
        this.jBtnCancel = jBtnCancel;
    }

    /**
     * @return the jBtnEdit
     */
    public javax.swing.JButton getjBtnEdit() {
        return jBtnEdit;
    }

    /**
     * @param jBtnEdit the jBtnEdit to set
     */
    public void setjBtnEdit(javax.swing.JButton jBtnEdit) {
        this.jBtnEdit = jBtnEdit;
    }

    /**
     * @return the jBtnExecSearch
     */
    public javax.swing.JButton getjBtnExecSearch() {
        return jBtnExecSearch;
    }

    /**
     * @param jBtnExecSearch the jBtnExecSearch to set
     */
    public void setjBtnExecSearch(javax.swing.JButton jBtnExecSearch) {
        this.jBtnExecSearch = jBtnExecSearch;
    }

    /**
     * @return the jBtnExit
     */
    public javax.swing.JButton getjBtnExit() {
        return jBtnExit;
    }

    /**
     * @param jBtnExit the jBtnExit to set
     */
    public void setjBtnExit(javax.swing.JButton jBtnExit) {
        this.jBtnExit = jBtnExit;
    }

    /**
     * @return the jBtnNew
     */
    public javax.swing.JButton getjBtnNew() {
        return jBtnNew;
    }

    /**
     * @param jBtnNew the jBtnNew to set
     */
    public void setjBtnNew(javax.swing.JButton jBtnNew) {
        this.jBtnNew = jBtnNew;
    }

    /**
     * @return the jBtnRemove
     */
    public javax.swing.JButton getjBtnRemove() {
        return jBtnRemove;
    }

    /**
     * @param jBtnRemove the jBtnRemove to set
     */
    public void setjBtnRemove(javax.swing.JButton jBtnRemove) {
        this.jBtnRemove = jBtnRemove;
    }

    /**
     * @return the jBtnSave
     */
    public javax.swing.JButton getjBtnSave() {
        return jBtnSave;
    }

    /**
     * @param jBtnSave the jBtnSave to set
     */
    public void setjBtnSave(javax.swing.JButton jBtnSave) {
        this.jBtnSave = jBtnSave;
    }

    /**
     * @return the jBtnSearch
     */
    public javax.swing.JButton getjBtnSearch() {
        return jBtnSearch;
    }

    /**
     * @param jBtnSearch the jBtnSearch to set
     */
    public void setjBtnSearch(javax.swing.JButton jBtnSearch) {
        this.jBtnSearch = jBtnSearch;
    }

    /**
     * @return the jLabelEditID
     */
    public javax.swing.JLabel getjLabelEditID() {
        return jLabelEditID;
    }

    /**
     * @param jLabelEditID the jLabelEditID to set
     */
    public void setjLabelEditID(javax.swing.JLabel jLabelEditID) {
        this.jLabelEditID = jLabelEditID;
    }

    /**
     * @return the jLabelSearchID
     */
    public javax.swing.JLabel getjLabelSearchID() {
        return jLabelSearchID;
    }

    /**
     * @param jLabelSearchID the jLabelSearchID to set
     */
    public void setjLabelSearchID(javax.swing.JLabel jLabelSearchID) {
        this.jLabelSearchID = jLabelSearchID;
    }

    /**
     * @return the jLayeredPaneControl
     */
    public javax.swing.JLayeredPane getjLayeredPaneControl() {
        return jLayeredPaneControl;
    }

    /**
     * @param jLayeredPaneControl the jLayeredPaneControl to set
     */
    public void setjLayeredPaneControl(javax.swing.JLayeredPane jLayeredPaneControl) {
        this.jLayeredPaneControl = jLayeredPaneControl;
    }

    /**
     * @return the jPanel1
     */
    public javax.swing.JPanel getjPanel1() {
        return jPanel1;
    }

    /**
     * @param jPanel1 the jPanel1 to set
     */
    public void setjPanel1(javax.swing.JPanel jPanel1) {
        this.jPanel1 = jPanel1;
    }

    /**
     * @return the jPanelEdit
     */
    public javax.swing.JPanel getjPanelEdit() {
        return jPanelEdit;
    }

    /**
     * @param jPanelEdit the jPanelEdit to set
     */
    public void setjPanelEdit(javax.swing.JPanel jPanelEdit) {
        this.jPanelEdit = jPanelEdit;
    }

    /**
     * @return the jPanelSearch
     */
    public javax.swing.JPanel getjPanelSearch() {
        return jPanelSearch;
    }

    /**
     * @param jPanelSearch the jPanelSearch to set
     */
    public void setjPanelSearch(javax.swing.JPanel jPanelSearch) {
        this.jPanelSearch = jPanelSearch;
    }

    /**
     * @return the jScrollPaneSearch
     */
   

    /**
     * @param jScrollPaneSearch the jScrollPaneSearch to set
     */
   

    /**
     * @return the jSepExit
     */
    public javax.swing.JToolBar.Separator getjSepExit() {
        return jSepExit;
    }

    /**
     * @param jSepExit the jSepExit to set
     */
    public void setjSepExit(javax.swing.JToolBar.Separator jSepExit) {
        this.jSepExit = jSepExit;
    }

    /**
     * @return the jSepSave
     */
    public javax.swing.JToolBar.Separator getjSepSave() {
        return jSepSave;
    }

    /**
     * @param jSepSave the jSepSave to set
     */
    public void setjSepSave(javax.swing.JToolBar.Separator jSepSave) {
        this.jSepSave = jSepSave;
    }

    /**
     * @return the jTableSearch
     */
    

    /**
     * @param jTableSearch the jTableSearch to set
     */
    

    /**
     * @return the jTextFieldEditID
     */
    public javax.swing.JTextField getjTextFieldEditID() {
        return jTextFieldEditID;
    }

    /**
     * @param jTextFieldEditID the jTextFieldEditID to set
     */
    public void setjTextFieldEditID(javax.swing.JTextField jTextFieldEditID) {
        this.jTextFieldEditID = jTextFieldEditID;
    }

    /**
     * @return the jTextFieldSearchID
     */
    public javax.swing.JTextField getjTextFieldSearchID() {
        return jTextFieldSearchID;
    }

    /**
     * @param jTextFieldSearchID the jTextFieldSearchID to set
     */
    public void setjTextFieldSearchID(javax.swing.JTextField jTextFieldSearchID) {
        this.jTextFieldSearchID = jTextFieldSearchID;
    }

    /**
     * @return the jToolBar1
     */
    public javax.swing.JToolBar getjToolBar1() {
        return jToolBar1;
    }

    /**
     * @param jToolBar1 the jToolBar1 to set
     */
    public void setjToolBar1(javax.swing.JToolBar jToolBar1) {
        this.jToolBar1 = jToolBar1;
    }

    @Action
    public void doInsert(){
        crudMstCtrl.insertRecord();
        clientes = new Clientes();
    }

    @Action
    public void doEdit(){
        crudMstCtrl.editRecord();
    }

    @Action
    public void doRemove(){
        crudMstCtrl.removeRecord();
    }

    @Action
    public void doSearch(){
        crudMstCtrl.searchRecord();
    }

    @Action
    public void doSave(){        

        clientes.setId(Integer.valueOf(jTextFieldEditID.getText()));
        clientes.setNome(jTextFieldEditNome.getText());

        System.out.println("ID --> "+clientes.getId());
        System.out.println("Nome --> "+clientes.getNome());
        System.out.println("Nascimento--> "+clientes.getNascimento());    

        instance.save(clientes);
        crudMstCtrl.saveRecordChanges();
        crudMstCtrl.searchRecord();
    }

    @Action
    public void doCancel(){
        crudMstCtrl.cancelRecordChanges();
    }

    @Action
    public void doExit(){
        crudMstCtrl.closeCrudWindow();
    }

    @Action
    public void doExecSearch(){
        controlJtable();
        /*
        clientes.setId(1);
        clientes.setNascimento(new Date("01/01/01"));
        clientes.setNome("Rafael Munhoz");
        System.out.println("Objeto Populado");
        System.out.println("id --> "+clientes.getId());
        System.out.println("nome --> "+clientes.getNome());
        System.out.println("data --> "+clientes.getNascimento());
        jTextFieldEditID.setText(Integer.toString(clientes.getId()));
        jTextFieldEditNome.setText(clientes.getNome());
        jFormattedTextFieldNasc.setText("01/01/2010");
        */
        
    }
    
    public List listAllRecords(){
        return crudMstCtrl.listAllRecords();
    }

    public void controlJtable(){

        String[][] content = new String[clientesList.size()][3];
        

        for(int i=0;i <clientesList.size();i++){
            content[i][0] = String.valueOf(clientesList.get(i).getId());
            content[i][1] = clientesList.get(i).getNome();
            if (clientesList.get(i).getNascimento() != null)
                content[i][2] = clientesList.get(i).getNascimento().toString();
        }

        

        jTableSearch.setModel(new javax.swing.table.DefaultTableModel(
                content,
                new String [] {
                "ID", "Nome","Nascimento"

            }));
    }    
}
